<?php

namespace App\Http\Middleware;

use Closure;

class CheckLogin
{
    /**
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // 检查用户是否登录
        if (!auth()->check()) {
            return redirect()->guest(route('admin.user.login'))->with(['status' => 1, 'msg' => '未登录']);
        }
        //检查用户是否访问可访问的权限
        if (!checkRoute($request)) {
            die('权限不足');
        }

        // 如果session中没有user则调到登录页，并提示
        //if (!session()->has('user')){
        //   return redirect()->route('admin.user.login')->with(['status'=>1,'msg'=>'未登录']);
        //}
        return $next($request);
    }
}
